/**
 * 滚动加载通用方法 201827  mxm
 */
define(function(require,exports,module) {
    var oScrollBox = $('.js_scrollBox');    // 滚动容器

    var oSideBox = $('.js_sideBox');        // 侧边按钮框
    var oGoTop = $('.js_goTop');            // 回到顶部

    var oScrollLoading = {
        minScrHeight: 200,
        time_ScrollBox : null,
        // 滚动加载数据
        ScrollPage: function (fn) {
            var _this = this;
            var oScrollBox = $('.js_scrollBox'); // 滚动容器
            oScrollBox.on('scroll', function () {
                var _$this = $(this);
                clearTimeout(_this.time_ScrollBox);
                _this.time_ScrollBox = setTimeout(function() {
                    var afterScroll = _$this.scrollTop();
                    var index = _$this.index(oScrollBox);
                    // 滚动距离底部高度
                    var nDis = oScrollBox[index].scrollHeight - afterScroll - oScrollBox.height();

                    _this.ShowGoTop(afterScroll);

                    if(nDis < _this.minScrHeight) {
                        if(fn)fn();
                    }

                },150);
            })
        },

        // 显示回到顶部按钮
        ShowGoTop: function (scrollTop) {
            scrollTop > 300 ? oSideBox.stop().animate({'right':0},300) : oSideBox.stop().animate({'right': '-3.5rem'},300);
        },



    }

    oGoTop.on('click', function (e) {
        oScrollBox.scrollTop(0);
        e.stopPropagation();
    });


    exports.oScrollLoading = oScrollLoading;

});

